package com.tsxy.mall.controller.api;

import com.tsxy.mall.entity.Recovery;
import com.tsxy.mall.entity.User;
import com.tsxy.mall.service.RecoveryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/api/recovery")
public class APIRecoveryController {
    @Autowired
    private RecoveryService recoveryService;

    @PostMapping("/add")
    public Integer add(@RequestBody Recovery recovery, HttpSession session){
        User user = (User)session.getAttribute("user");
        recovery.setUser(String.valueOf(user.getId()));
        return recoveryService.add(recovery);
    }

    @GetMapping("/getList")
    public List getAll(HttpSession session){
        Recovery recovery = new Recovery();
        recovery.setUser(String.valueOf( ((User)session.getAttribute("user")).getId() )  );
        return recoveryService.getList(recovery);
    }
}
